package com.test.wog.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.test.wog.bean.Node;
import com.test.wog.dao.NodeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 关键节点的服务层
 *
 * @author linxun @buaa.edu.cn
 * @since 2020-01-26
 * @see Node
 * @see NodeDAO
 */
@Service
public class NodeService {
    @Autowired
    private NodeDAO nodeDAO;

    /**
     * 根据名称查询关键节点
     *
     * @param name 节点名称
     * @return 名称为name的全部关键节点
     */
    public String getNodeByName(String name){
        List<Node> nodeList = nodeDAO.getNodeByName(name);
        String jsonString = JSONArray.toJSONString(nodeList, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        return jsonString;
    }

    /**
     *
     *
     * @param type the type
     * @return the string
     */
    /*根据POI类型进行查询*/
    public String getNodeByType(String type){
        List<Node> nodeList = nodeDAO.getNodeByType(type);
        String jsonString = JSONArray.toJSONString(nodeList, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        return jsonString;
    }

    /**
     * Get node by loc string.
     *
     * @param lon the lon
     * @param lat the lat
     * @return the string
     */
    /*根据经纬度查询最近的一个POI*/
    public String getNodeByLoc(double lon, double lat){
        List<Node> nodeList = nodeDAO.getNodeByLoc(lon, lat);
        String jsonString = JSONArray.toJSONString(nodeList, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        return jsonString;
    }

    /**
     * Get all node string.
     *
     * @return the string
     */
    /*查询有所的关键点*/
    public String getAllNode(){
        List<Node> nodeList = nodeDAO.getAllNode();
        String jsonString = JSONArray.toJSONString(nodeList, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        return jsonString;
    }


    /**
     * Insert node int.
     *
     * @return the int
     */
    public int insertNode(){
        return nodeDAO.insertNode();
    }
}
